package LC;

/**
 * https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
 * Given a binary tree, find its maximum depth.
 * The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
 */
public class LC_104_MaximumDepthofBinaryTree_Recur_BinaryTree {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        int depth = Solution.maxDepth(root);
        System.out.println(depth);
    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class Solution {
        static int maxDepth(TreeNode root) {
            return root == null ? 0 : (1 + Math.max(maxDepth(root.left), maxDepth(root.right)));
        }
    }
}
